package org.hismig.test.utils;

import java.util.HashMap;
import java.util.Map;

import junit.framework.TestCase;

import org.hismig.utils.StringTool;

/**
 * @declare: //TODO <br />
 *           This class created by Vansion.Hopihit on 2012-07-04 <br />
 *           <a href="mailto:vansionhopihit@gmail.com">Contact Me</a>
 * @version 1.0
 * @author Vansion.Hopihit
 * 
 */
public class StringToolTester extends TestCase {

	public void testTrimBlank() {

		String str = " i am vansion.hopihit ";

		assertEquals("i am vansion.hopihit", StringTool.trimBlank(str));

		str = "hello\r\n\t world";
		assertEquals("hello world", StringTool.trimBlank(str));
	}
	
	public void testConvertBoolean() {
		String str_true = "tRue";
		String str_false = "falSE";
		
		assertTrue(StringTool.convertToBoolean(str_true, false));
		assertFalse(StringTool.convertToBoolean(str_false, true));
		
		assertTrue(StringTool.convertToBoolean("helloworld", true));
		assertTrue(StringTool.convertToBoolean("", true));
		assertTrue(StringTool.convertToBoolean(null, true));
	}
	
	public void testNiceWord() {

		assertEquals("first", StringTool.niceWord("first"));
		assertEquals("first", StringTool.niceWord("First"));
		assertEquals("f", StringTool.niceWord("F"));
		assertEquals("", StringTool.niceWord(""));
		assertNull(StringTool.niceWord(null));
	}
	
	public void testEvaluate() {
		
		assertTrue(StringTool.evaluate("#{1 == 1}", null));
		assertTrue(StringTool.evaluate("#{1 eq 1}", null));
		assertFalse(StringTool.evaluate("#{1 < 0}", null));
		assertFalse(StringTool.evaluate("#{1 lt 0}", null));
		
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("day", "2000-01-01");
		
		assertTrue(StringTool.evaluate("#{day ge '1999-99-99'}", map));
		assertTrue(StringTool.evaluate("#{day lt '2012-99-99'}", map));
		
	}

}
